import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/index'

// 全局样式
import '@/styles/index.less';
import '@/assets/iconfont/iconfont.css'

// 引入动画
import animated from 'animate.css';
Vue.use(animated);

// 引入ViewUI组件
import ViewUI from '@/commont/plugins/viewUI';
import 'view-design/dist/styles/iview.css';
Vue.use(ViewUI);

// 引入ElementUI组件
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

//  引入Echarts：想要引入中国地图，版本不能高于5.0
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;
require('echarts/map/js/china.js');
require('echarts/map/js/world.js');

// 引入jQuery
// import $ from 'jquery'

// 引用bootstrap
// import 'bootstrap/dist/css/bootstrap.min.css'
// import 'bootstrap/dist/js/bootstrap.min.js'

// 引入Vant组件 - 移动端
import Vant, { Lazyload,Notify,Toast,Dialog,ImagePreview } from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);
Vue.use(Lazyload); //图片懒加载
Vue.use(Notify); //消息通知
Vue.use(Toast); //轻提示
Vue.use(Dialog); //弹出消息
Vue.use(ImagePreview); //图片预览

// 引入富文本框
import VueQuillEditor from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
Vue.use(VueQuillEditor);

// js工具类(时间戳转换，数组去重，浏览器信息的获取等.....)
import jutils from 'jutils-src';
Vue.use(jutils);

// 运行mock
require('./mock/index');

// 字体自适应
import { setSize } from '@/commont/utils/setSize';
window.onresize = () => {
  // setSize();
}

// 将公共方法挂在到vue原型链上
import util from '@/commont/utils/index'
Vue.prototype.$util = util;

// 自动锁屏引入
// import Astrict from '@/commont/utils/astrict';
// Vue.use(Astrict);

Date.prototype.format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1,               //月份
    "d+": this.getDate(),                    //日
    "h+": this.getHours(),                   //小时
    "m+": this.getMinutes(),                 //分
    "s+": this.getSeconds(),                 //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    "S": this.getMilliseconds()             //毫秒
  };
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for (var k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    }
  }
  return fmt;
}

// 树结构数组重组
Array.prototype.totree = function (attributes) {
  attributes = Object.assign({
    id: '_id',
    pid: 'pid',
    rootId: 0
  }, attributes)
  if ((this instanceof Array) && this.length > 0) {
    var resData = JSON.parse(JSON.stringify(this)),
    tree = [];
    for (var i = 0; i < resData.length; i++) {
      if (resData[i][attributes.pid] == attributes.rootId) {
        // resData[i]["children"] = new Array();
        var obj = resData[i];
        tree.push(obj);
        resData.splice(i, 1);
        i--;
      }
    }
    function run(chiArr) {
      if (resData.length !== 0) {
        for (var i = 0; i < chiArr.length; i++) {
          for (var j = 0; j < resData.length; j++) {
            if (chiArr[i][attributes.id] == resData[j][attributes.pid]) {
              // resData[j]["children"] = new Array()
              var obj = resData[j];
              if (!chiArr[i].children) {
                chiArr[i]["children"] = new Array();
              }
              chiArr[i].children.push(obj);
              resData.splice(j, 1);
              j--;
            }
          }
          var child = chiArr[i].children || [];
          run(child);
        }
      }
    }
    run(tree);
    return tree;
  } else {
    return new Array();
  }
}

Vue.config.productionTip = false;

// new Vue({
//   router,
//   store,
//   render: h => h(App)
// }).$mount('#app')

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
